package cn.endowment.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;



public class SessionInterceptor implements HandlerInterceptor{
	
	private ThreadLocal<Long> time=new ThreadLocal<Long>();
	Logger log=Logger.getLogger("SessionInterceptor");

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		log.debug("preHandle");
		time.set(System.currentTimeMillis());
		/*if(request.getSession().getAttribute("userName")==null || request.getSession().getAttribute("userName")==""){
			log.debug("login illegal");
			return false;
		}*/
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		log.debug("postHandle");
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
	
		log.debug("afterCompletion");
		log.debug(System.currentTimeMillis()-time.get()+"");
	}

}
